package com.yisin.pbox.frame.init;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.yinsin.server.TcpServerSocket;
import com.yisin.pbox.frame.common.RootContext;
import com.yisin.pbox.frame.log.ILogger;
import com.yisin.pbox.frame.log.LogFactory;
import com.yisin.pbox.frame.util.StringUtil;
import com.yisin.www.chat.ChatServlet;

public class ServerInit implements ServletContextListener {
	private static final long serialVersionUID = 1L;
	ILogger logger = LogFactory.getDefaultLogger(ServerInit.class);

	public void contextDestroyed(ServletContextEvent arg0) {

	}

	public void contextInitialized(ServletContextEvent arg0) {
		ConfigManager.getInstance().initServletContext(arg0.getServletContext());
		
		int serverPort = StringUtil.stringToInt(ConfigManager.getInstance().getConfig("JsSocketServerPort"), 8283);
		String serverIp = ConfigManager.getInstance().getConfig("JsSocketServerIp");
		TcpServerSocket tsc = TcpServerSocket.getInstance();
		tsc.setIp(serverIp);
		tsc.startServer(serverPort, ChatServlet.getChat());
	}


}
